// 导入
import { request } from "../../request/index.js";
Page({
    data: {
        // 轮播图数据
        swiperList:[],
        // 导航数据
        catesList:[],
        // 楼层数据
        floorList:[]
    },
    /**
     * 页面加载时 发请求获取数据
     * @param {*} options 
     */
    onLoad: function(options){
        this.getSwiperList();
        this.getCatesList();
        this.getFloorList();
    },
    getSwiperList(){
      /*   wx.request({
            url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
            success: (result)=>{
              this.setData({
                  swiperList: result.data.message
              })    
            }
        }); */
        request({url:'/home/swiperdata'})
        .then(res=>{
            res.forEach(v => {
                v.navigator_url = v.navigator_url.replace(/main/,"index");
            });
            this.setData({
                swiperList: res
            })     
        });

    },
    getCatesList(){
   
        request({url:'/home/catitems'})
        .then(res=>{
            this.setData({
                catesList: res
            })     
        });

    },
    getFloorList(){
   
        request({url:'/home/floordata'})
        .then(res=>{
            res.forEach(v=>{
                v.product_list.forEach(v2=>{
                    v2.navigator_url=v2.navigator_url.replace(/\?/,"/index?")
                })
            })
            this.setData({
                floorList: res
            })     
        });

    }
 
});